import { AuthService } from './auth.service';
import { Injectable } from '@angular/core';
export const MenuList: any[] = [
	{
		router: '/page/warehouse/warehouse-index',
		icon: 'setting',
		name: '仓库',
		auth: []
	},
	{
		router: '/page/tool/tool-type',
		icon: 'layout',
		name: '种类',
		auth: []
	},
	{
		router: '/page/user/user-index',
		icon: 'setting',
		name: '人员',
		auth: []
	},
	{
		router: '',
		icon: 'area-chart',
		name: '量具台账',
		auth: [],
		children: [
			{
				router: '/page/tool/tool-account',
				name: '量具台账',
				auth: [],
			}
		]
	},

];

@Injectable({
	providedIn: 'root'
})
export class MenuService {
	private menuList = MenuList;
	constructor(
		private authService: AuthService
	) { }


	getMenu() {
		const auth = this.authService.getAuth();
		this.menuList.forEach(it => {
			it.hidden = false;
			if (!it?.children?.length) {
				if (!it.auth.some(au => auth.includes(au))) {
					it.hidden = true;
				}
			} else {
				it.children.forEach(childIt => {
					childIt.hidden = false;
					if (!childIt.auth.some(au => auth.includes(au))) {
						childIt.hidden = true;
					}
				});
			}
		});
		return this.menuList;
	}


	isLoadMenu(url: string): boolean {
		// for (let i = 0; i < this.menuList.length; i++) {
		// 	const menu = this.menuList[i];
		// 	if (menu.router.includes(url)) {
		// 		return !menu.hidden;
		// 	}
		// 	if (menu?.children?.length) {
		// 		const menuChild = menu?.children.find(c => c.router.includes(url));
		// 		if (menuChild) {
		// 			return !menuChild.hidden;
		// 		}
		// 	}
		// }
		return true;
	}

}
